<template>
  <el-container class="model_index">
    <el-main class="model-tree" style="padding-bottom:10;padding-top:10">
      <el-card shadow="never" class="model-tree-left">
        <span style="font-size:14px;font-weight: 700;">组织架构</span>
        <el-tree
          ref="tree"
          class="treeitems"
          :data="departmentTreeList"
          :props="defaultProps"
          :default-expanded-keys="defaultList"
          :highlight-current="true"
          :check-on-click-node="true"
          :expand-on-click-node="false"
          default-expand-all
          node-key="id"
          style="margin-top: 10px;"
          :current-node-key="currentNodekey"
          @node-click="handleNodeClick"
        />
      </el-card>
      <div class="model-tree-right">
        <el-card shadow="never" class="tableCard">
          <vxe-toolbar :refresh="{ query: getList1 }">
            <template v-slot:buttons>
              <el-button type="primary" icon="el-icon-plus" @click="openDialog('', 1, false)">新增</el-button>
            </template>
          </vxe-toolbar>
          <vxe-table
            ref="xTree"
            text-algin="center"
            border
            stripe
            resizable
            highlight-hover-row
            :loading="loading"
            :data="list"
            :auto-resize="true"
            :height="$store.getters.searchRow"
          >
            <vxe-table-column field="code" width="120" title="员工代码" />
            <vxe-table-column field="name" width="180" title="员工名称" />
            <vxe-table-column field="positionName" width="150" title="员工职务" />
            <vxe-table-column field="mobile" width="160" title="联系手机" />
            <vxe-table-column field="genderDesc" width="80" title="性别" />
            <vxe-table-column field="email" width="250" title="个人邮箱" />
            <vxe-table-column field="statusDesc" min-width="80" align="center" title="在职状态" />
          </vxe-table>
          <vxe-pager
            :current-page.sync="params.pageNum"
            :page-size.sync="params.pageSize"
            :total="total"
            :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total']"
            @page-change="getList"
          />
        </el-card>
      </div>
    </el-main>
  </el-container>
</template>

<script>
import { getEffectDepartmentListTree, getEmployeePageList} from '@/api/org/organize'
export default {
  data() {
    return {
      orgPositionList: [],
      dialogFormVisible: false,
      title: '',
      params: {
        code: '',
        name: '',
        departmentId: '',
        positionId: '',
        mobile: '',
        gender: 1,
        remark: ''
      },
      queryParams: {
        departmentId: 0,
        pageNum: 1,
        pageSize: 20
      },
      defaultProps: {
        children: 'children',
        label: 'name',
        value: 'id'
      },
      currentNodekey: '',
      defaultList: [{
        id: 1
      }],
      departmentTreeList: [],
      loading: false,
      total: 0,
      list: []
    }
  },
  created() {
    this.getDepartmentListTree()
  },
  methods: {
    getDepartmentListTree() {
      getEffectDepartmentListTree({}).then((response) => {
        this.currentNodekey = response[0].id
        this.departmentTreeList = [...response]
        this.$nextTick(() => {
          this.$refs.tree.setCurrentKey(this.currentNodekey)
          this.handleNodeClick({ id: this.currentNodekey })
        })
      })
    },
    handleNodeClick(data) {
      // if (!data.children) {
      this.currentNodekey = data.id
      this.queryParams.departmentId = data.id
      this.getList()
      this.getPositionSelect()
      // }
    },
    getList1() {
      this.getList()
    },
    // 重置参数
    refreshParams(queryP) {
      this.queryParams = queryP
      this.getList()
    },
    getList() {
      getEmployeePageList(this.queryParams).then(res => {
        this.total = res.total
        this.list = res.records
      })
    }
  }
}
</script>

<style>
.model_index {
  .model-tree {
    display: flex;
    .model-tree-left {
      margin-right: 20px;
      min-width: 250px;
      height: 640px;
      overflow-y: auto;
      .el-tree-node.is-current > .el-tree-node__content {
        background-color: #2F8DFB !important;
        color: white;
      }
    }
    .model-tree-right {
      width: calc(100% - 280px);
    }
  }
}
</style>
